package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.exceptions.LyException;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper , SpecParam> implements SpecParamService {



    @Override
    public List<SpecParamDTO> queryParam(Long categoryId, Long groupId, Boolean searching) {
        //判断数据，如空报错
        if (categoryId == null && groupId == null){
            throw new LyException( 400 , "查询条件不能为空,至少有一个");
        }
        //查看是否有数据，有就查询没有就查询有的
        List<SpecParam> lsit = query().eq(categoryId != null, "category_id" ,categoryId)
                .eq(groupId != null ,"group_id" ,groupId)
                .eq(searching != null ,"searching" ,searching).list();
        //返回
        return SpecParamDTO.convertEntityList(lsit);
    }
}
